import { Body, Controller, Get, Param, Post, Query, Delete, Put } from '@nestjs/common'
import { MerchantService } from './merchant.service'
@Controller('merchant')
export class MerchantController {
    constructor(private readonly merchantService: MerchantService) {}
    // 获取商家列表
    @Post('getMerchantInfo')
    async getMerchant(@Body() body:any) {
        const { merChantName } = body;
        let searchList = [];
        if (merChantName) {
            searchList.push({ merchant: { $regex: merChantName } });
        }
        let data = await this.merchantService.getMerchantInfo(searchList)

        let data2 = await this.merchantService.getMerchantInfo([])
        let merchantCate = [{
            value: '',
            label: '请选择',
        }]
        data2.map((item: any) => {
            merchantCate.push({ value: item.merchant, label: item.merchant })

        })

        return {
            code: 200,
            data: data,
        }
    }
    //添加商家信息
    @Post("addMerchantInfo")
    async addMerchantInfo(@Body() body: any) {
        this.merchantService.addMerchantInfo(body)
        return {
            code: 200,
            msg: "添加成功",
        }
    }

    //删除商家信息
    @Delete("deleteMerchantInfo")
    async deleteMerchantInfo(@Body() data: any) {
        this.merchantService.deleteMerchantInfo(data)
        return {
            code: 200,
            msg: "删除成功",
        }
    }

    //修改商家信息
    @Put("updateMerchantInfo")
    async updateMerchantInfo(@Body() body:any){
        this.merchantService.updateMerchantInfo(body)
        return{
            code:200,
            msg:"修改成功"
        }
    }
    
}
